<template>
    <h2>登录页面</h2>
    <table border="1">
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="info.ULname" /></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" v-model="info.ULpwd"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="Ulogin">登录</button>
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref} from'vue'
import { useRouter } from 'vue-router';
const router = useRouter();
const info = ref({
    ULname:'',
    ULpwd:''
})
const Ulogin=()=>{
    if(info.value.ULpwd==""){
        alert("密码不能为空")
        return 
    }
    axios.get("https://localhost:44396/api/User/Ulogin",
        {
            params:{
                ULname:info.value.ULname,
                ULpwd:info.value.ULpwd
            }
        }
    ).then(res=>{
        if(res.data==-1){
            alert("用户名不存在")
        }else if(res.data==-2){
            alert("密码错误")
        }else if(res.data==1){
            alert("登录成功")
            router.push("/ShowUser")
        }else{
            alert("登录失败")
        }
    })
}

</script>